#include "tire.h"

const float Tire::rotationFactor = 0.5f;

Tire::Tire(const Cube& cube,const ObjectModelPtr& model)
	: SceneObject(cube,model){
	this->rotationAngle=0;
	this->rotationSpeed=0;
}

Tire::~Tire(){
}

void Tire::setModelMatrix(){
	this->getParent().setSubModelMatrix();

	Point tr = this->dimensions.center();
	glTranslatef(tr.x1,tr.x2,tr.x3);
	glScalef(this->dimensions.width(),this->dimensions.depth(),this->dimensions.height());
	glRotatef(-this->rotationAngle*180/PI,1,0,0);
	glRotatef(90,0,0,1);
}

void Tire::timeStep(){
	this->rotationSpeed = this->speed.mod()*Tire::rotationFactor;
	this->rotationAngle += this->rotationSpeed;
	if(this->rotationAngle<0)
		this->rotationAngle=0;
	else if(this->rotationAngle>2*PI)
		this->rotationAngle -= 2*PI;
}
